<?php

namespace app\api\controller;

use app\admin\controller\Exception;
use app\BaseController;

class Study extends BaseController
{


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function study_report()
    {
        $list_rows = $this->request->param('list_rows', '10', 'trim');
        $page = $this->request->param('page', '1', 'trim');
        $classes_id = $this->request->param('classes_id', '', 'trim');
        $student_id = $this->request->param('student_id', '', 'trim');
        $time = $this->request->param('time', '', 'trim');

        $data = [
            'classes_id' => $classes_id,
            'student_id' => $student_id,
            'list_rows' => $list_rows,
            'page' => $page,
            'time' => $time . '',
        ];

        $data = array_filter($data);
        try {
            $study_reportObj = new \app\common\business\StudyReport();
            $result = $study_reportObj->study_report($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_study_report()
    {
        $id = $this->request->param('id', '', 'trim');

        try {
            $study_reportObj = new \app\common\business\StudyReport();
            $result = $study_reportObj->one_study_report($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function subject()
    {
        try {
            $subjectObj = new \app\common\business\Subject();
            $result = $subjectObj->subject();
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function courseware()
    {
        $list_rows = $this->request->param('list_rows', '10', 'trim');
        $page = $this->request->param('page', '1', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');

        $data = [
            'subject_id' => $subject_id,
            'list_rows' => $list_rows,
            'page' => $page,
        ];

        $data = array_filter($data);
        try {
            $coursewareObj = new \app\common\business\Courseware();
            $result = $coursewareObj->courseware($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_courseware()
    {
        $id = $this->request->param('id', '', 'trim');

        try {
            $coursewareObj = new \app\common\business\Courseware();
            $result = $coursewareObj->one_courseware($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function exercises()
    {
        $list_rows = $this->request->param('list_rows', '10', 'trim');
        $page = $this->request->param('page', '1', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');

        $data = [
            'subject_id' => $subject_id,
            'list_rows' => $list_rows,
            'page' => $page,
        ];

        $data = array_filter($data);
        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->exercises($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_exercises()
    {
        $id = $this->request->param('id', '10', 'trim');

        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->one_exercises($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_answer()
    {
        $exercises_id = $this->request->param('exercises_id', '10', 'trim');
        $user_id = ($this->request->userInfo)['id'];
        $data = [
            'exercises_id' => $exercises_id,
            'user_id' => $user_id,
        ];

        try {
            $answerObj = new \app\common\business\Answer();
            $result = $answerObj->one_answer($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function edit_answer()
    {
        $exercises_id = $this->request->param('exercises_id', '', 'trim');
        $answer = $this->request->param('answer', '', 'trim');
        $user_id = ($this->request->userInfo)['id'];

        $where_data = [
            'exercises_id' => $exercises_id,
            'user_id' => $user_id,
        ];

        try {
            $exercisesObj = new \app\common\business\Exercises();
            $result = $exercisesObj->edit_answer($where_data,$answer);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function note()
    {
        $list_rows = $this->request->param('list_rows', '10', 'trim');
        $page = $this->request->param('page', '1', 'trim');
        $subject_id = $this->request->param('subject_id', '', 'trim');
        $user_type = $this->request->param('user_type', '2', 'trim');
        $user_id = ($this->request->userInfo)['id'];

        $data = [
            'subject_id' => $subject_id,
            'list_rows' => $list_rows,
            'page' => $page,
            'user_type' => $user_type,
            'user_id' => $user_id,
        ];

        $data = array_filter($data);
        try {
            $noteObj = new \app\common\business\Note();
            $result = $noteObj->note($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }


    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function add_note()
    {
        $title = $this->request->param('title', '', 'trim');
        $ps = $this->request->param('ps', '', 'trim');
        $user_id = ($this->request->userInfo)['id'];
        $user_type = $this->request->param('user_type', '2', 'trim');

        $data = [
            'title' => $title,
            'ps' => $ps,
            'user_id' => $user_id,
            'user_type' => $user_type,
        ];

        try {
            $noteObj = new \app\common\business\Note();
            $result = $noteObj->add_note($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }



    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function edit_note()
    {
        $id = $this->request->param('id', '', 'trim');
        $title = $this->request->param('title', '', 'trim');
        $ps = $this->request->param('ps', '', 'trim');
        $content = $this->request->param('content', '', 'trim');

        $data = [
            'id' => $id,
            'title' => $title,
            'ps' => $ps,
            'content' => $content,
        ];

        $data = array_filter($data);
        try {
            $noteObj = new \app\common\business\Note();
            $result = $noteObj->edit_note($data);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function del_note()
    {
        $id = $this->request->param('id', '', 'trim');

        try {
            $noteObj = new \app\common\business\Note();
            $result = $noteObj->del_note($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }

    /**
     * 2025 03 04
     * Administrator
     * @return \think\response\Json
     */
    public function one_note()
    {
        $id = $this->request->param('id', '10', 'trim');

        try {
            $noteObj = new \app\common\business\Note();
            $result = $noteObj->one_note($id);
            return show(config('common.http_status.success'), 'ok', $result);
        } catch (Exception $e) {
            return show($e->getCode(), $e->getMessage());
        }
    }
}